<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel">
    <qc-report-form
      v-if="disableSubmit"
      ref="realForm"
      @ok="submitCallback"
      :disabled="disableSubmit"
      :report-type="reportType" />
    <qc-report-batch-form
      v-else
      ref="realForm"
      @ok="submitCallback"
      :report-type="reportType" />
  </j-modal>
</template>

<script>

import QcReportForm from './QcReportForm'
import QcReportBatchForm from './QcReportBatchForm.vue'

export default {
  name: 'QcReportModal',
  components: {
    QcReportBatchForm,
    QcReportForm
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      reportType: ''
    }
  },
  methods: {
    edit(record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })
    },
    detail(record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.detail(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.handleSubmit()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped>
</style>